//下列三行代码,为刚需,此提供了下列所有代码的入口
'use strict';
 
goog.provide('Blockly.Arduino.SpriteBot');//注意脚本类别及路径名称
goog.require('Blockly.Arduino');
 
Blockly.Arduino.forBlock['Demo1'] = function () {
  return "";
};
 //include模块
Blockly.Arduino.SpriteBot_include = function() {
    var INCLUDE = this.getFieldValue('INCLUDE');//使用INCLUDE 变量来存储,block文件夹中的OLED.js脚本,文本输入对象的值
    Blockly.Arduino.definitions_['define_'+INCLUDE] = '#include "SpriteBot.h" //引用机器人库';//严格函数,固定写法(转include调用内容)
    return '';
};
 
 //配置构造函数模块
Blockly.Arduino.config = function() {
  	Blockly.Arduino.definitions_['define_'] = 'SpriteBot spriteBot;//生成一个新的对象实例\n';
    return '';
};
 
//初始化SpriteBoti
Blockly.Arduino.initSpriteBot = function() {
    Blockly.Arduino.setups_['setup_init'] = 'spriteBot.Init();//初始化\n';//严格函数固定写法(转setup函数中代码)
    return '';
};
//初始化SpriteBoti
Blockly.Arduino.initController = function() {
  Blockly.Arduino.setups_['setup_init'] = 'spriteBot.Init();//初始化\n  spriteBot.enableRCController();//启用遥控器\n';//严格函数固定写法(转setup函数中代码)
  return '';
};

Blockly.Arduino.forBlock['move_stop'] = function () {

  
  var code = '';
  code += 'spriteBot.stop();\n'+'delay(1000);\n';
  return code;
};

Blockly.Arduino.forBlock['move_front'] = function () {

  
  var code = '';
  code += 'spriteBot.front();\n'+'delay(1000);\n';
  return code;
};
Blockly.Arduino.forBlock['move_left'] = function () {

  
  var code = '';
  code += 'spriteBot.left();\n'+'delay(1000);\n';
  return code;
};

Blockly.Arduino.forBlock['move_right'] = function () {

  
  var code = '';
  code += 'spriteBot.right();\n'+'delay(1000);\n';
  return code;
};

Blockly.Arduino.forBlock['move_back'] = function () {

  
  var code = '';
  code += 'spriteBot.back();\n'+'delay(1000);\n';
  return code;
};
Blockly.Arduino.forBlock['pose_control_list'] = function () {

  var cmd = this.getFieldValue('cmd');
  var count = Blockly.Arduino.valueToCode(this, 'count', Blockly.Arduino.ORDER_ASSIGNMENT)|| '5';
  count=count*1000;
  var code = '';
  code += 'spriteBot.move('+ cmd + ');\n' +'delay('+ + count   + ');\n';
  return code;
};
Blockly.Arduino.forBlock['Distance'] = function () {

  var count = Blockly.Arduino.valueToCode(this, 'count', Blockly.Arduino.ORDER_ATOMIC)|| '5';
  var code = 'spriteBot.getDistance()<'+count+' && spriteBot.getDistance()>5';
  return [code, Blockly.Arduino.ORDER_ATOMIC];
};




